package com.microcity.autocomponent.autoview.viewex;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2017/5/17.
 */

public class SimpleWatchView extends View {

    private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    public SimpleWatchView(Context context) {
        this(context, null, 0);
    }

    public SimpleWatchView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);

    }

    public SimpleWatchView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint();
    }

    private void initPaint() {
        mPaint.setColor(Color.BLACK);
        mPaint.setStyle(Paint.Style.STROKE);
//        mPaint.setStrokeWidth(10);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        initWatch(canvas);
    }

    private void initWatch(Canvas canvas) {

        canvas.translate(canvas.getWidth() / 2, 200);
//        canvas.drawPoint(0, 0, mPaint);
        canvas.drawCircle(0, 0, 100, mPaint);

        canvas.save();
        canvas.translate(-75, -75);
        canvas.drawPoint(0, 0, mPaint);
        Path path = new Path();
        path.addArc(new RectF(0, 0, 150, 150), -180, 180);
        Paint citePaint = new Paint(mPaint);
        citePaint.setTextSize(14);
        citePaint.setStrokeWidth(1);
        canvas.drawTextOnPath("http://www.android777.com", path, 28, 0, citePaint);
        canvas.restore();//返回到上次保存的位置 即cancas.save();之前的配置
//        canvas.drawPoint(0, 0, mPaint);

        Paint tmpPaint = new Paint(mPaint);
        tmpPaint.setStrokeWidth(1);
        float y = 100;
        int count = 60;

        for (int i = 0; i < count; i++) {
            if (i%5 == 0) {
                canvas.drawLine(0,y,0,y + 12f,mPaint);
                canvas.drawText(String.valueOf(i/5 + 1),-4f,y + 25f,tmpPaint);
            } else {
                canvas.drawLine(0,y,0,y + 5f,tmpPaint);
            }
            canvas.rotate(360/count,0,0);

            canvas.drawPoint(0,200,mPaint);
        }

//        canvas.rotate(60,0,0);//旋转坐标系  并不是旋转整个画布
//        canvas.drawPoint(0,200,mPaint);

        //画指针
        tmpPaint.setColor(Color.GRAY);
        tmpPaint.setStrokeWidth(4);
        canvas.drawCircle(0,0,7,tmpPaint);
        tmpPaint.setColor(Color.BLACK);
        tmpPaint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(0,0,5,tmpPaint);
        canvas.drawLine(0,10,0,-65,tmpPaint);
        canvas.rotate(30,0,0);//神器
        canvas.drawLine(0,10,0,-35,tmpPaint);

    }
}
